package forward.Module.Modules.Combat;

import forward.Module.Module;
import forward.Module.ModuleType;
import forward.UI.ClientNotification;
import forward.Util.ClientUtil;
import forward.Util.MSTimer;
import forward.Util.PlayerUtil;
import forward.api.EventAttack;
import forward.api.EventHandler;
import forward.api.Value.Mode;
import forward.api.Value.Numbers;
import forward.api.Value.Option;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.network.play.client.C0BPacketEntityAction;

public class SuperKnockback extends Module {
    public static Mode mode = new Mode("Mode", "mode", (Enum[]) kbMode.values(), (Enum) kbMode.Extrapacket);
    private static Numbers<Double> hurtTime = new Numbers<Double>("hurtTime", "hurtTime", 10.0, 0.0, 10.0, 1.0);

    private static Numbers<Double> delay = new Numbers<Double>("delay", "delay", 0.0, 0.0, 500.0, 1.0);
    private Option<Boolean> onlyMove = new Option<Boolean>("onlyMove", "onlyMove", false);
    private Option<Boolean> onlyGround = new Option<Boolean>("onlyGround", "onlyGround", false);
    MSTimer timer=new MSTimer();

    public SuperKnockback() {
        super("SuperKnockback", new String[]{"SuperKnockback"}, ModuleType.Combat);
        this.addValues(mode,delay,hurtTime,onlyGround,onlyMove);
    }
    @EventHandler
    public void onAttack(EventAttack event){
        ClientUtil.sendClientMessage("WSSB.", ClientNotification.Type.SUCCESS);
        if (event.getEntity() instanceof EntityLivingBase) {
            if (((EntityLivingBase) event.getEntity()).hurtTime >
                    hurtTime.getValue() ||
                    !timer.hasTimePassed((long)delay.getValue().doubleValue()) ||
                    (!PlayerUtil.isMoving() && onlyMove.getValue()) ||
                    (!Minecraft.getMinecraft().thePlayer.onGround && onlyGround.getValue())) {
                return;
            }
            if (mode.getValue()==kbMode.Extrapacket){
                if (Minecraft.getMinecraft().thePlayer.isSprinting()) {
                    Minecraft.getMinecraft().thePlayer.setSprinting(true);
                }
                Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0BPacketEntityAction(Minecraft.getMinecraft().thePlayer, C0BPacketEntityAction.Action.STOP_SPRINTING));
                Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0BPacketEntityAction(Minecraft.getMinecraft().thePlayer, C0BPacketEntityAction.Action.START_SPRINTING));
                Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0BPacketEntityAction(Minecraft.getMinecraft().thePlayer, C0BPacketEntityAction.Action.STOP_SPRINTING));
                Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0BPacketEntityAction(Minecraft.getMinecraft().thePlayer, C0BPacketEntityAction.Action.START_SPRINTING));
                Minecraft.getMinecraft().thePlayer.serverSprintState = true;

            } else if (mode.getValue()==kbMode.Wtap) {
                if (Minecraft.getMinecraft().thePlayer.isSprinting()) {
                    Minecraft.getMinecraft().thePlayer.setSprinting(false);
                }
                Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0BPacketEntityAction(Minecraft.getMinecraft().thePlayer, C0BPacketEntityAction.Action.START_SPRINTING));
                Minecraft.getMinecraft().thePlayer.serverSprintState = true;
            } else if (mode.getValue()==kbMode.Packet) {
                if (Minecraft.getMinecraft().thePlayer.isSprinting()) {
                    Minecraft.getMinecraft().thePlayer.setSprinting(true);
                }
                Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0BPacketEntityAction(Minecraft.getMinecraft().thePlayer, C0BPacketEntityAction.Action.STOP_SPRINTING));
                Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C0BPacketEntityAction(Minecraft.getMinecraft().thePlayer, C0BPacketEntityAction.Action.START_SPRINTING));
                Minecraft.getMinecraft().thePlayer.serverSprintState = true;
            }
            timer.reset();
        }
    }
    enum kbMode{
        Extrapacket,Wtap,Packet;
    }
}
